using Light.Assets.Scripts.EventManager;
using Refresh;
using UnityEngine;

namespace Light
{
    public class SkillsController_Event : MonoBehaviour
    {
        private void Awake()
        {
            EventManager.Register<StatusBarEvent>(OnStatusBarEventTrigger);
        }

        #region StatusBarEvent

        private void OnStatusBarEventTrigger(StatusBarEvent @event)
        {
            switch (@event.BarType)
            {
                case FunctionBarType.Skill:
                    OnGoodsFunctionBarTrigger(@event);
                    break;
            }

            @event.Dispose();
        }

        private void OnGoodsFunctionBarTrigger(StatusBarEvent @event)
        {
            switch (@event.BarOperationType)
            {
                case FunctionBarOperationType.Init:
                    GoodsFunctionBarInit(@event);
                    break;
            }
        }

        private void GoodsFunctionBarInit(StatusBarEvent @event)
        {
            @event.contentTypes.ForEach(type =>
            {
                if (type == FunctionBarContentType.SkillsBarView) SkillsItemListInit();
            });
        }

        private void SkillsItemListInit()
        {
            var info = StatusBarInfo.Get();

            //���ó�ʼ����
            //TODO���һ����������
            info.type = FunctionBarType.Skill;
            info.contentType = FunctionBarContentType.SkillsBarView;

            foreach (var item in SkillsManager.GetSkillsItemData())
                info.operations.Add((new SkillsBarData { data = item, type = item.type },
                    FunctionBarOperationType.Add));
            var parentPanel = UIManager.Instance.GetPanel<StatusBarPanel>("StatusBarPanel");
            parentPanel.skillPanel.Refresh(info);
        }

        #endregion StatusBarEvent
    }
}